package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogToyHouseEliminate;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogToyHouseEliminateDaoImpl extends TempDao {

    public boolean addLogToyHouseEliminateList(List<LogToyHouseEliminate> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_toy_house_eliminate(userId,activityId,multi,beforeEnergy,costEnergy,bombUse1,count1,bombCreate1,score1,maxCon,count2,bombCreate2,score2,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogToyHouseEliminate data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMulti()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBeforeEnergy()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCostEnergy()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBombUse1()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCount1()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBombCreate1()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getScore1()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMaxCon()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCount2()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBombCreate2()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getScore2()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
